﻿<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>前锋图书管理系统</title>
    <link rel="stylesheet" href="/css/public.css"/>
    <link rel="stylesheet" href="/css/style.css"/>
</head>
<style>
    html,body{
        width: 100%;
        height: 100%;
    }
    .homeWrap{
        width: 100%;height: 100%;
        padding-top: 76px;position: relative;box-sizing: border-box;overflow: hidden;
    }
    .homeWrap div{box-sizing: border-box;}
    .publicMian,.left{height: 100%;}
    .homeHeader{width: 100%; position: absolute;left: 0;top: 0;}
</style>
<body style="line-height: 24px;font: 14px Helvetica Neue,Helvetica,PingFang SC,\5FAE\8F6F\96C5\9ED1,Tahoma,Arial,sans-serif;">
<!--头部-->
<div class="homeWrap">
    <div class="homeHeader">
        <header class="publicHeader">
            <h1>前锋图书管理系统</h1>
            <div class="publicHeaderR">
                <p><span>下午好！</span><span style="color: #fff21b"> Admin</span> , 欢迎你！</p>
                <a href="/admin/index/signOut">退出</a>
            </div>
        </header>

    <!--时间-->
        <section class="publicTime">
            <span id="time">2015年1月1日 11:11  星期一</span>
        </section>
    </div>
<!--主体内容-->
    <section class="publicMian" style="height: 655px;">
        <div class="left">
            <h2 class="leftH2"><span class="span1"></span>功能列表 <span></span></h2>
            <nav>
                <ul class="list">
                    <li><a href="/admin/home/home">首页</a></li>
                    <li><a href="/admin/home/borrowingmanagement">借阅管理</a></li>
                    <li><a href="/admin/home/bookrecord">图书记录</a></li>
                    <li><a href="/admin/home/bookadd">图书添加</a></li>
                    <li><a href="/admin/scrollmember/scroll">滚屏</a></li>
                    <li id="active"><a href="/admin/scrollmember/member">会员管理</a></li>
                    <li><a href="/admin/home/editpass">修改密码</a></li>
                    <li><a href="/admin/home/groupbuy">团队来源</a></li>
                </ul>
            </nav>
        </div>
        <div class="right">
            <div class="location">
                <strong>你现在所在的位置是:</strong>
                <span>会员管理页面</span>
            </div>
            <div class="search">
                <span>搜索：</span>
                <input type="text" placeholder="请输入用户名" id="content"/>
                <input type="button" value="查询" id="search" />
                <input type="button" value="添加" onclick="addUser()" style="float: right;margin-top: 10px;background: #47acf1;"/>
            </div>
            <!--用户-->
            <div class="userlist"></div>
        </div>
        <!--分页-->
        <div class="pagePage" style="top: 670px;">
            <div class="page_control">
                <div class="pagination"></div>
            </div>
        </div>
    </section>
</div>
<script src="/js/jquery.js"></script>
<script src="/js/js.js"></script>
<script src="/js/time.js"></script>
<script src="/js/layer/layer.js"></script>
<script src="/js/jquery.paging.js"></script>
<script>
    // 弹出添加框
    function addUser(){
        $("#username").val('');   // 用户姓名
        $("#useraccounts").val('');   // 用户帐号

        layer.open({
            type: 1,
            title: '请添加用户信息',
            area: ['402px', '272px', '-116.5px', '334.5px'],
            shadeClose: true, //点击遮罩关闭
            content:'<div class="remove">' +
            '<div class="removerChid">' +
            '<div class="removeMain">' +
            '<div class="search" style="background: #ffffff;padding-left: 0;">' +
            '<span>姓名：</span>' +
            '<input type="text" placeholder="请输入姓名" id="username"/>' +
            '</div>' +
            '<div class="search" style="background: #ffffff;padding-left: 0;">' +
            '<span>帐号：</span>' +
            '<input type="text" placeholder="请输入帐号" id="useraccounts"/>' +
            '</div>' +
            '<div class="search" style="background: #ffffff;padding-left: 0;">' +
            '<input type="button" value="添加" onclick="useAjax()" style="width: 248px;background: #47acf1;"/>'+
            '</div>' +
            '</div>' +
            '</div>' +
            '</div>'
        });
    }
    // 确认添加用户
    function useAjax(){
        var username = $("#username").val();   // 用户姓名
        var useraccounts = $("#useraccounts").val();   // 用户帐号
        // alert(useraccounts+username);
        if(username==''){
            layer.msg('请填写姓名');
        }
        else if(useraccounts==''){
            layer.msg('请填写账号');
        }
        else{
            $.ajax({
                url:'/admin/Scrollmember/member',
                type:'POST',
                data:{
                    username:username,
                    useraccounts:useraccounts,
                },
                success:function(res){
                    $("#addUser").css("display","none");
                    if(res == 1){
                        layer.msg('添加成功');
                        window.location.href = '/admin/scrollmember/member';
                    }
                    else if(res == 2){
                        layer.msg('本帐号已注册，无需再次注册');
                    }
                    else{
                        layer.msg('添加失败');
                        window.location.href = '/admin/scrollmember/member';
                    }
                },
                error:function(){

                }
            });
        }
    }
</script>
<script>
    $('.pagination').paging({
        total: '',
        currentPage: '',
        showPage: 5,        //显示的页数
        animation: false,
        showJump: false,
        ajaxSubmitType: 'post',
        simpleType: 1,
        url: '/admin/Scrollmember/memberArr',
        idParameter: "page",
        ajaxData: {'pageSize': 1},
        beforeAjaxSubmit: function () {
            PageAPI.AddAjaxData({"pageSize": $(".pageSize").val()});
        },
        ajaxSubmitBack: function (data) {
            console.log(data);
            $('.userlist').empty();
            var orderinfo = data.data;
            if(orderinfo=='' ||orderinfo==undefined){
                $(".userlist").html(' <h2 style="text-align: center;padding-top:120px;height: 166px;color: red;">暂无数据</h2>');
                $(".pagination").hide();
            }else{
                $(".pagination").show();
                var infohtml='';
                infohtml+='<table class="providerTable" cellpadding="0" cellspacing="0">';
                infohtml+='<tr class="firstTr"><th width="10%">姓名</th><th width="20%">帐号</th><th width="20%">操作</th></tr>';
                $.each(orderinfo,function(index,value){
                    infohtml+='<tr style="width:40px;">';
                    infohtml+='<td>'+value['name']+'</td>';
                    infohtml+='<td>'+value['account']+'</td>';
                    infohtml+='<td>';
                    if(value['ustates'] == 1){
                        infohtml += '<input type="button" onclick="stopUser('+value['id']+')" value="停用" class="anniu"/>';
                        infohtml += '<input type="button" onclick="resetPass('+value['id']+')" value="初始密码" class="anniu" style="width: 60px;"/>';
                    }
                    else{
                        infohtml += '<input type="button" onclick="startUser('+value['id']+')" value="启用" class="anniu"/>';
                        infohtml += '<input type="button" onclick="resetPass('+value['id']+')" value="初始密码" class="anniu" style="width: 60px;visibility: hidden;"/>';
                    }
                    infohtml+='</td></tr>';
                })
                infohtml+='</table>';
                $('.userlist').html(infohtml);
            }
        },
        ajaxFormatBack: function (data) {
            data.total = data.totalpage;
            data.currentPage = data.currentPage;
        }
    });
</script>
<script>
    // 帐号停用
    function stopUser(id){
        $.ajax({
            url:'/admin/Scrollmember/stopUser',
            type:'POST',
            data:{
                id:id,
            },
            success:function(res) {
                if (res == 1) {
                    layer.msg('帐号已停用');
                    window.location.href = '/admin/scrollmember/member';
                }
                else {
                    layer.msg('帐号停用失败');
                }
            }
        });
    }
    // 重置密码
    function resetPass(id){
        $.ajax({
            url:'/admin/Scrollmember/resetPass',
            type:'POST',
            data:{
                id:id,
            },
            success:function(res) {
                if (res == 1) {
                    layer.msg('密码已重置');
                }
                else {
                    layer.msg('密码还是初始密码');
                }
            }
        });
    }
    // 账号启用
    function startUser(id){
        $.ajax({
            url:'/admin/Scrollmember/startUser',
            type:'POST',
            data:{
                id:id,
            },
            success:function(res) {
                if (res == 1) {
                    layer.msg('帐号已启用');
                    window.location.href = '/admin/scrollmember/member';
                }
                else {
                    layer.msg('帐号启用失败');
                }
            }
        });
    }
    // 搜索
    $('#search').click(function(){
        var name = $('#content').val();
        if(name!=''){
            searchPage(name)
        }
    })
    // 搜索分页
    function searchPage(name){
        $(".pagination").empty();
        $('.pagination').paging({
            total: '',
            currentPage: '',
            showPage: 5,        //显示的页数
            animation: false,
            showJump: false,
            ajaxSubmitType: 'post',
            simpleType: 1,
            url: '/admin/index/search',
            idParameter: "page",
            ajaxData: {'pageSize': 1,name:name,type:1},
            beforeAjaxSubmit: function () {
                PageAPI.AddAjaxData({"pageSize": $(".pageSize").val()});
            },
            ajaxSubmitBack: function (data) {
                console.log(data);
                $('.userlist').empty();
                var orderinfo = data.data;
                if(orderinfo=='' ||orderinfo==undefined){
                    $(".userlist").html(' <h2 style="text-align: center;padding-top:120px;height: 166px;color: red;">暂无数据</h2>');
                    $(".pagination").hide();
                }else{
                    $(".pagination").show();
                    var infohtml='';
                    infohtml+='<table class="providerTable" cellpadding="0" cellspacing="0">';
                    infohtml+='<tr class="firstTr"><th width="10%">姓名</th><th width="20%">帐号</th><th width="20%">操作</th></tr>';
                    $.each(orderinfo,function(index,value){
                        infohtml+='<tr style="width:40px;">';
                        infohtml+='<td>'+value['name']+'</td>';
                        infohtml+='<td>'+value['account']+'</td>';
                        infohtml+='<td>';
                        if(value['ustates'] == 1){
                            infohtml += '<input type="button" onclick="stopUser('+value['id']+')" value="停用" class="anniu"/>';
                            infohtml += '<input type="button" onclick="resetPass('+value['id']+')" value="初始密码" class="anniu" style="width: 60px;"/>';
                        }
                        else{
                            infohtml += '<input type="button" onclick="startUser('+value['id']+')" value="启用" class="anniu"/>';
                        }
                        infohtml+='</td></tr>';
                    })
                    infohtml+='</table>';
                    $('.userlist').html(infohtml);
                }
            },
            ajaxFormatBack: function (data) {
                data.total = data.totalpage;
                data.currentPage = data.currentPage;
            }
        });
    }

</script>
</body>
</html>